<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div style="padding: 5px;">
	<form class="form-horizontal" role="form">
		<div class="form-group">
			<div class="row">
				<label for="commnetedContent" class="col-sm-1 control-label">评价内容:</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" id="commnetedContent">
				</div>
				<label for="commentCompany" class="col-sm-2 control-label">评价人所属单位:</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" id="commentCompany">
				</div>
				<div class="col-sm-2">
					<button type="button" class="btn btn-primary no-border btn-sm" id="searchBtn">
						<span class="fa fa-search"></span>查询
					</button>
				</div>
			</div>
		</div>
	</form>
	<div id="commentGrid" class="commentGrid"></div>
</div>
<script>
	$(function() {
		var cols = [{
			title : '评价人',
			name : 'commenterName',
			width : '150px'
		}, {
			title : '手机号码',
			name : 'mobilePhone',
			width : '150px'
		}, {
			title : '评价人所属单位',
			name : 'commentCompany',
			width : '150px'
		}, {
			title : '体验满意度',
			name : 'useSat',
			width : '200px',
			render : function(item, name, index) {
				return '<div id="useSatRating" class="starts"><div class="defaultStars" style="background-position: '+(parseInt(item[name])-5)*30+'px -30px;"></div></div>'
			}
		}, {
			title : '客服满意度',
			name : 'customerServiceSat',
			width : '200px',
			render : function(item, name, index) {
				return '<div id="useSatRating" class="starts"><div class="defaultStars" style="background-position: '+(parseInt(item[name])-5)*30+'px -30px;"></div></div>'
			}
		}, {
			title : '评语',
			name : 'comment',
			width : '150px'
		}, {
			title : '评价时间',
			name : 'createTime',
			width : '150px',
			render: function(item, name, index){
				return getTimeStr(item[name]);
			}
		}];
		var buttons = [{
			content : '<button class="btn btn-info no-border btn-sm" type="button"><span class="fa fa-search"></span>查看</button>',
			action : 'view'
		}, {
			content : '<button class="btn btn-primary no-border btn-sm" type="button"><span class="fa fa-plus"></span>&nbsp;新增</button>',
			action : 'add'
		}, {
			content : '<button class="btn btn-success no-border btn-sm" type="button"><span class="fa fa-pencil-square-o"></span>&nbsp;修改</button>',
			action : 'modify'
		}, {
			content : '<button class="btn btn-danger no-border btn-sm" type="button"><span class="fa fa-trash-o"></span>&nbsp;删除</button>',
			action : 'delete'
		}, {
			content : '<button class="btn btn-default no-border btn-sm" type="button"><span class="fa fa-download"></span>&nbsp;导出</button>',
			action : 'export'
		}];
		$('#commentGrid').grid({
			identity : 'id',
			columns : cols,
			buttons : buttons,
			url : contextPath + '/commentRepair/query'
		}).on({
			'view' : function(event, data) {
				var indexs = data.data;
				var $this = $(this);
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择一条记录进行修改'
					})
					return;
				}
				if (indexs.length > 1) {
					$this.message({
						type : 'warning',
						content : '只能选择一条记录进行修改'
					})
					return;
				}
				seajs.use('commentRepair', function(commentRepair) {
					commentRepair.view(indexs[0], $this);
				});
			},
			'add' : function() {
				seajs.use('commentRepair', function(commentRepair) {
					commentRepair.add();
				});
			},
			'modify' : function(event, data) {
				var indexs = data.data;
				var $this = $(this);
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择一条记录进行修改'
					})
					return;
				}
				if (indexs.length > 1) {
					$this.message({
						type : 'warning',
						content : '只能选择一条记录进行修改'
					})
					return;
				}
				seajs.use('commentRepair', function(commentRepair) {
					commentRepair.modify(indexs[0], $this);
				});
			},
			'delete' : function(event, data) {
				var indexs = data.data;
				var $this = $(this)
				if (indexs.length == 0) {
					$this.message({
						type : 'warning',
						content : '请选择要删除的记录'
					})
					return;
				}
				$this.confirm({
					content : '确定要删除所选记录吗?',
					callBack : function() {
						seajs.use('commentRepair', function(commentRepair) {
							commentRepair.remove(indexs, $this);
						});
					}
				});
			},
			'export': function(){
				var searchCondition = $(this).getGrid().searchCondition;
				var data = [];
				for(var prop in searchCondition){
					if(searchCondition[prop] && searchCondition[prop].length > 0){
						data.push(prop + '=' + searchCondition[prop]);
					}
				}
				window.open(contextPath + '/commentRepair/exportExcel'+ (data.length == 0 ? '' : '?'+data.join('&')), "导出工单");
			}
		});
		$('#searchBtn').on('click', function() {
			seajs.use('util', function(util) {
				$('#commentGrid').getGrid().search(util.getFormData(pageContents.find('form')));
			});
		});
	}); 
</script>
